package cn.qy.java.base.ch21;

/**
 * join 使用
 */
public class Ch21_04_ThreadJoin {
	
	public static void main(String[] args) throws InterruptedException {
		
		class Thread1 extends Thread {
			
			long millis;
			
			public Thread1(String name, long millis) {
				super(name);
				this.millis = millis;
			}

			public void run() {
				try {
					Thread.sleep(millis);
				} catch (InterruptedException e) {
					e.printStackTrace();
				}
				System.out.println(this.getName() + " end");
			};
		};
		
		Thread t1 = new Thread1("Thread 1", 3000);
		Thread t2 = new Thread1("Thread 2", 1000);

		t1.start();
		t2.start();

		// 当前线程将等待 t 执行完, 主线程才能继续
		System.out.println("t1.join");
		t1.join();
		// 当前线程将等待 t 执行完, 主线程才能继续
		t2.join();
		
		System.out.println("main end");
	}

}
